import React from 'react';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import {
  Card,
  Button,
  Row,
  Col,
  Modal,
  Form,
  Checkbox,
  Tabs,
  Space,
  Badge,
  Select,
  DatePicker,
  Input,
  Radio,
  Dropdown,
  InputNumber,
  message,
  Menu,
  Drawer,
} from 'antd';
import {
  PlusOutlined,
  CloseOutlined,
  CodepenOutlined,
  DownOutlined,
  ExclamationCircleOutlined,
  FileOutlined,
  CopyOutlined,
  SettingOutlined,
} from '@ant-design/icons';
import JobTree from './jobTreeN';
import { connect } from 'umi';
import moment from 'moment';
import {
  ResourceGrpSelect,
  OpMasterSelect,
  ResourceSelect,
  EmpSelect,
} from '@/components/FormItemSelect';
import PartSelect from '@/components/PartSelect';
import JobSelect from '@/components/JobSelect';
import ItemSelect from '@/components/ItemSelect';
import request from '@/utils/request';
import DocHelper from '@/components/DocHelper';

const { TabPane } = Tabs;
const { confirm } = Modal;
const apiURL = '/api/services/app/JobHead/';
const apiURLAsm = '/api/services/app/JobAsmbl/';
const apiURLMtl = '/api/services/app/JobMtl/';
const apiURLOper = '/api/services/app/JobOper/';
class ViewPage extends React.Component<any, any> {
  constructor(props: any) {
    super(props);
    this.state = {
      loading: false,
      visible: false,
      dataSource: [],
      JobHead: {
        jobCompleted: true,
        jobReleased: true,
        jobClosed: true,
        jobType: ''
      },
      JobAsmbl: {},
      JobMtl: {},
      JobOper: {},
      defTab: '1',
    };
  }
  formRef: any = React.createRef();
  onFinishFailed = (errorInfo: any) => {
    let jobErr = 0;
    let jobMtlErr = 0;
    let jobAsmErr = 0;
    let jobOprErr = 0;
    errorInfo.errorFields.forEach((element: any) => {
      if (element.name[0] == 'JobMtl') {
        jobMtlErr++;
      } else if (element.name[0] == 'JobAsmbl') {
        jobAsmErr++;
      } else if (element.name[0] == 'JobOper') {
        jobOprErr++;
      } else if (element.name[0] == 'JobHead') {
        jobErr++;
      }
      this.setState({ jobErr, jobMtlErr, jobAsmErr, jobOprErr });
    });
  };
  onFinish = (values: any) => {
    const JobHead = values.JobHead;
    const JobMtl = values.JobMtl;
    const JobAsmbl = values.JobAsmbl;
    const JobOper = values.JobOper;
    const data: any = {};
    if (JobHead) {
      this.saveJobHead(JobHead);
      data.jobNum = JobHead.jobNum;
    }
    if (JobAsmbl) {
      this.saveJobData(JobAsmbl, apiURLAsm);
      data.jobNum = JobAsmbl.jobNum;
    }
    if (JobMtl) {
      this.saveJobData(JobMtl, apiURLMtl);
      data.jobNum = JobMtl.jobNum;
    }
    if (JobOper) {
      JobOper.opDesc = JobOper.opCode;
      this.saveJobData(JobOper, apiURLOper);
      data.jobNum = JobOper.jobNum;
    }
    this.setState({ jobErr: 0, jobMtlErr: 0, jobAsmErr: 0, jobOprErr: 0 });
  };
  saveJobHead = (JobHead: any) => {
    const { BomData } = this.state
    JobHead.dueDate = JobHead.dueDate?.format('YYYY-MM-DD');
    JobHead.startDate = JobHead.startDate?.format('YYYY-MM-DD');
    let act = 'New';
    let method = 'POST';
    if (JobHead.id) {
      act = 'Update';
      method = 'PUT';
    }
    request(apiURL + act, {
      method: method,
      data: JobHead,
    }).then((response) => {
      if (response && response.success) {
        BomData.JobHead = response.result;
        message.success('保存成功！');        
      }
      this.setState({ loading: false });
    });
  };
  saveJobData = (data: any, api: string) => {
    let act = 'New';
    let method = 'POST';

    if (data.id) {
      act = 'Update';
      method = 'PUT';
    }
    request(api + act, {
      method: method,
      data: data,
    }).then((response) => {
      if (response && response.success) {
        message.success('保存成功！');
        this.editBomData(act, api, response.result)
      }
      this.setState({ loading: false });
    });
  };
  editBomData = (act: string, api: string, data: any) => {
    const { BomData, JobHead } = this.state
    if (act === 'New') {
      if (api.includes('JobMtl'))
        BomData.mtls.push(data)
      else if (api.includes('JobOper'))
        BomData.boos.push(data)
      else
        BomData.boms.push(data)
    }
    else if (act === 'Del') {
      if (api.includes('JobMtl')) {
        BomData.mtls = BomData.mtls.filter((o: any) => o.id != data.id)
        this.formRef.current.setFieldsValue({ JobMtl: null });
      }
      else if (api.includes('JobOper')) {
        BomData.boos = BomData.boos.filter((o: any) => o.id != data.id)
        this.formRef.current.setFieldsValue({ JobOper: null });
      }
      else {
        BomData.boms = BomData.boms.filter((o: any) => o.id != data.id)
        this.formRef.current.setFieldsValue({ JobAsmbl: null });
      }
    }
    else {
      if (api.includes('JobMtl')) {
        var items = BomData.mtls.filter((o: any) => o.id != data.id)
        items.push(data)
        BomData.mtls = items
      }
      else if (api.includes('JobOper')) {
        var items = BomData.boos.filter((o: any) => o.id != data.id)
        items.push(data)
        BomData.boos = items
      }
      else {
        var items = BomData.boms.filter((o: any) => o.id != data.id)
        items.push(data)
        BomData.boms = items
      }
    }
    this.bomTree.fetchData(BomData, JobHead)
  }
  bomTree: any = JobTree;
  onRef = (ref: any) => {
    this.bomTree = ref;
  };
  setCurrent = (part?: any) => {
    let JobHead: any = {};
    JobHead.partNum = part.partNum;
    JobHead.partDescription = part.partDescription;
    JobHead.ium = part.ium;
    this.formRef.current.setFieldsValue({ JobHead });
    this.setState({ partRevs: part.revs });
  };
  setCurrent2 = (part?: any) => {
    let JobMtl: any = {};
    JobMtl.partNum = part.partNum;
    JobMtl.partDescription = part.partDescription;
    JobMtl.ium = part.ium;
    this.formRef.current.setFieldsValue({ JobMtl });
  };
  setCurrent3 = (part?: any) => {
    let JobAsmbl: any = {};
    JobAsmbl.partNum = part.partNum;
    JobAsmbl.partDescription = part.partDescription;
    JobAsmbl.ium = part.ium;
    this.formRef.current.setFieldsValue({ JobAsmbl });
    this.setState({ partRevs2: part.revs });
  };
  getObj = (e: any) => {
    if (e.jobNum) {
      this.setState({ loading: true });
      request(apiURL + 'GetBomData', {
        method: 'GET',
        params: { jobNum: e.jobNum },
      }).then((response) => {
        if (response) {
          if (response.success) {
            if (response.result) {
              let BomData = response.result;
              let JobHead = response.result.jobHead;
              this.setState({ BomData, JobHead });
              if (JobHead.dueDate) JobHead.dueDate = moment(JobHead.dueDate);
              if (BomData.boms[0]) {
                let JobAsmbl = BomData.boms[0];
                this.setCurrentAsmb(JobAsmbl, 'asm');
                if (BomData.boos[0]) {
                  let JobOper = BomData.boos[0];
                  this.setCurrentAsmb(JobOper, 'boo');
                  if (BomData.mtls[0]) {
                    let JobMtl = BomData.mtls[0];
                    this.setCurrentAsmb(JobMtl, 'mtl');
                  }
                }
              }
              this.setCurrentAsmb(JobHead, 'root');
              this.bomTree.fetchData(BomData, JobHead);
            } else {
              message.error(e.jobNum + '不存在');
            }
          } else {
            message.error(response.error.message);
          }
          this.setState({ loading: false });
        }
      });
    }
  };
  fetchBom = () => {
    const { JobHead } = this.state;
    this.setState({ loading2: true });
    request(apiURL + 'FetchBom', {
      method: 'POST',
      params: {
        jobNum: JobHead.jobNum,
        partNum: JobHead.partNum,
        revNum: JobHead.revisionNum,
      },
    }).then((response) => {
      if (response && response.success) {
        this.getObj(JobHead);
      }
      this.setState({ loading2: false });
    });
  };
  setCurrentAsmb = (item: any, type: string, node: any = null) => {
    if (type === 'mtl') {
      this.setState({ JobMtl: item, defTab: '2' });
      this.formRef.current.setFieldsValue({ JobMtl: item });
    } else if (type === 'asm') {
      let boos: any = node?.children?.filter((o: any) => o.type === 'boo')
      this.setState({ JobAsmbl: item, booList: boos, defTab: '3' });
      this.formRef.current.setFieldsValue({ JobAsmbl: item });
    } else if (type === 'boo') {
      this.setState({ JobOper: item, defTab: '4' });
      this.formRef.current.setFieldsValue({ JobOper: item });
    } else {
      this.setState({ JobHead: item, defTab: '1' });
      this.formRef.current.setFieldsValue({ JobHead: item });
    }
  };
  tabSwitch = (key: any) => {
    this.setState({ defTab: key });
  };
  selectOpr = (e: any) => {
    const obj = this.state.booList.filter((o: any) => o.item.oprSeq == e)[0];
    if (obj) {
      const JobMtl: any = {};
      JobMtl.relatedOpRev = obj.item.revisionNum;
      this.formRef.current.setFieldsValue({ JobMtl });
    }
  };
  resetForm = () => {
    this.formRef.current.resetFields();
    this.setState({
      BomData: [],
      JobHead: {
        jobCompleted: false,
        jobReleased: false,
        jobClosed: false,
      },
    });
    this.bomTree.clearData();
    this.setState({ jobErr: 0, jobMtlErr: 0, jobAsmErr: 0, jobOprErr: 0 });
  }
  handleMenuClick = (e: any) => {
    const { JobHead, JobAsmbl } = this.state;
    if (e.key === '1') {
      this.resetForm();
    } else if (e.key === '2') {
      if (!JobAsmbl.id) {
        message.warning('请先选择半成品');
        return;
      }
      this.formRef.current.setFieldsValue({ JobMtl: null });
      let JobMtl = {
        jobNum: JobHead.jobNum,
        assemblySeq: JobAsmbl.assemblySeq,
        qtyPer: JobAsmbl.requiredQty,
      };
      this.formRef.current.setFieldsValue({ JobMtl });
    } else if (e.key === '3') {
      if (!JobAsmbl.id) {
        message.warning('请先选择上级半成品');
        return;
      }
      this.formRef.current.setFieldsValue({ JobAsmbl: null });
      let _JobAsmbl = {
        jobNum: JobHead.jobNum,
        parent: JobAsmbl.partNum,
        qtyPer: JobAsmbl.requiredQty,
      };
      this.formRef.current.setFieldsValue({ JobAsmbl: _JobAsmbl });
    } else if (e.key === '5') {
      this.setState({ loading: true });
      request(apiURL + 'CopyJob', {
        method: 'POST',
        params: { jobNum: JobHead.jobNum },
      }).then((response) => {
        if (response.success) {
          message.success('复制成功');
          this.getObj(response.result);
          this.setState({ loading: false });
        }
      });
    }
    else {
      if (!JobAsmbl.id) {
        message.warning('请先选择半成品');
        return;
      }
      this.formRef.current.setFieldsValue({ JobOper: null });
      let _JobOper = {
        jobNum: JobHead.jobNum,
        assemblySeq: JobAsmbl.assemblySeq,
        partNum: JobAsmbl.partNum,
        partDescription: JobAsmbl.partDescription,
        revisionNum: JobAsmbl.revisionNum,
      };
      this.formRef.current.setFieldsValue({ JobOper: _JobOper });
    }
    this.setState({ defTab: e.key });
  };
  delObj = () => {
    const { defTab, JobAsmbl, JobOper, JobMtl, JobHead } = this.state;
    let ctrl = 'PartBom';
    let id = 0;
    if (defTab == '2') {
      ctrl = 'JobMtl';
      id = JobMtl.id;
    } else if (defTab == '3') {
      ctrl = 'JobAsmbl';
      id = JobAsmbl.id;
    } else if (defTab == '4') {
      ctrl = 'JobOper';
      id = JobOper.id;
    } else {
      ctrl = 'JobHead';
      id = JobHead.id;
    }
    let _this = this;
    confirm({
      title: '警告',
      icon: <ExclamationCircleOutlined />,
      content: '删除后将不可恢复，确定删除？',
      onOk() {
        request(apiURL.replace('JobHead', ctrl) + 'DelPatch', {
          method: 'POST',
          data: [id],
        }).then((response) => {
          if (ctrl != 'JobHead')
            _this.editBomData('Del', ctrl, { id })
          else
            _this.resetForm();
        });
      },
    });
  };
  setSoCurrent = (item: any) => {
    var obj = this.formRef.current.getFieldsValue();
    if (obj.JobHead.partNum != item.partNum) {
      message.warning('订单与生产产品编码不符');
      return;
    }
    let model = {
      orderNum: item.orderNum,
      orderLine: item.orderLine,
      orderRelNum: item.orderRelNum,
      prodQty: item.ourReqQty,
      dueDate: moment(item.requestDate),
    };
    this.formRef.current.setFieldsValue({ JobHead: model });
  };
  setJobHeadParent = (item: any) => {
    let obj = this.formRef.current.getFieldsValue();
    if (obj.JobHead.jobNum == item.jobNum) {
      message.warning('错误！不能选择当前工单。');
      return;
    }
    if (obj.JobHead.partNum != item.partNum) {
      message.warning('错误！产品编码不符。');
      return;
    }
    let JobHead = {
      parentJobNum: item.jobNum,
      parentJobMtl: item.jobSeq,
      parentJobAsmbl: item.assemblySeq,
      prodQty: item.requiredQty,
    };
    this.formRef.current.setFieldsValue({ JobHead });
  };
  switchDraw = () => {
    const { visible } = this.state;
    this.setState({ visible: !visible });
  };
  releaseJob = (e: any) => {
    const { JobHead } = this.state;
    if (JobHead.id) {
      request(apiURL + 'ReleaseJob', {
        method: 'POST',
        params: { id: JobHead.id, val: e.target.checked },
      }).then((response) => {
        if (response.success) {
          this.getObj(JobHead);
        }
      });
    }
  };
  setAutoJob = (e: any) => {
    let isAuto = e.target.checked;
    let JobHead = {
      jobNum: isAuto ? '0' : ''
    }
    this.setState({ isAuto });
    this.formRef.current.setFieldsValue({ JobHead });
  }
  render() {
    const layout = {
      labelCol: { span: 3 },
      wrapperCol: { span: 15 },
    };
    const {
      BomData,
      defTab,
      loading,
      loading2,
      booList,
      JobHead,
      jobErr,
      jobMtlErr,
      jobAsmErr,
      jobOprErr,
      isAuto,
    } = this.state;
    const jobType = this.state?.jobType || JobHead.jobType;
    const disEdit = JobHead.jobCompleted || JobHead.jobClosed || JobHead.jobReleased;
    const disFetch = JobHead.jobReleased;
    const selectRev = (
      <Select placeholder="选择版本">
        {this.state.partRevs?.map((item: any) => {
          return (
            <Select.Option key={item} value={item}>
              {item}
            </Select.Option>
          );
        })}
      </Select>
    );
    const selectRev2 = (
      <Select placeholder="选择版本">
        {this.state.partRevs2?.map((item: any) => {
          return (
            <Select.Option key={item} value={item}>
              {item}
            </Select.Option>
          );
        })}
      </Select>
    );
    const columnOrderRel = [
      {
        title: '订单号',
        dataIndex: 'orderNum',
        width: 80,
      },
      {
        title: '分录',
        dataIndex: 'orderLine',
        width: 60,
      },
      {
        title: '发货行',
        dataIndex: 'orderRelNum',
        width: 80,
      },
      {
        title: '物料编码',
        dataIndex: 'partNum',
        width: 100,
      },
      {
        title: '描述',
        dataIndex: 'lineDesc',
        ellipsis: true,
      },
      {
        title: '需求量',
        dataIndex: 'ourReqQty',
        width: 80,
      },
      {
        title: '需求日期',
        dataIndex: 'requestDate',
        width: 100,
        render: (text: Date) => moment(text).format('YYYY-MM-DD'),
      },
    ];
    const columnJobItem = [
      {
        title: '工单号',
        dataIndex: 'jobNum',
      },
      {
        title: '半成品号',
        dataIndex: 'assemblySeq',
      },
      {
        title: '物料号',
        dataIndex: 'jobSeq',
      },
      {
        title: '物料编码',
        dataIndex: 'partNum',
      },
      {
        title: '描述',
        dataIndex: 'partDescription',
      },
      {
        title: '需求量',
        dataIndex: 'requiredQty',
      },
      {
        title: '单位',
        dataIndex: 'ium',
      },
    ];
    return (
      <PageHeaderWrapper title={false}>
        <Drawer
          width={600}
          placement="right"
          closable={false}
          visible={this.state.visible}
          onClose={this.switchDraw}
          getContainer={false}
          mask={false}
          maskClosable={false}
          footer={
            <Button type="primary" onClick={this.switchDraw}>
              关闭
            </Button>
          }
        >
          <JobTree onRef={this.onRef} BomData={BomData} setCurrentAsmb={this.setCurrentAsmb} />
        </Drawer>
        <Form
          {...layout}
          ref={this.formRef}
          onFinish={this.onFinish}
          onFinishFailed={this.onFinishFailed}
        >
          <Row gutter={[16, 16]}>
            <Col xs={24} sm={24} md={24} lg={24} xl={24}>
              <Card loading={loading} >
                <Space>
                  <Dropdown
                    overlay={
                      <Menu onClick={this.handleMenuClick}>
                        <Menu.Item key="1" icon={<PlusOutlined />}>
                          新建工单
                        </Menu.Item>
                        <Menu.Item
                          key="2"
                          icon={<FileOutlined />}
                          disabled={JobHead.jobNum === '0'}
                        >
                          新建物料
                        </Menu.Item>
                        <Menu.Item
                          key="3"
                          icon={<CodepenOutlined />}
                          disabled={JobHead.jobNum === '0'}
                        >
                          新建半成品
                        </Menu.Item>
                        <Menu.Item
                          key="4"
                          icon={<SettingOutlined />}
                          disabled={JobHead.jobNum === '0'}
                        >
                          新建工序
                        </Menu.Item>
                        <Menu.Item
                          key="5"
                          icon={<CopyOutlined />}
                          disabled={JobHead.jobNum === '0'}
                        >
                          复制工单
                        </Menu.Item>
                      </Menu>
                    }
                  >
                    <Button type="primary" icon={<PlusOutlined />}>
                      新建 <DownOutlined />
                    </Button>
                  </Dropdown>
                  <Button
                    key="2"
                    type="primary"
                    loading={loading}
                    htmlType="submit"
                    disabled={disEdit}
                  >
                    保存
                  </Button>
                  <Button
                    key="3"
                    type="primary"
                    onClick={this.fetchBom}
                    loading={loading2}
                    disabled={disFetch}
                  >
                    提取BOM
                  </Button>
                  <Button
                    key="4"
                    type="dashed"
                    danger
                    icon={<CloseOutlined />}
                    onClick={this.delObj}
                    disabled={disEdit}
                  >
                    删除
                  </Button>
                  <Button key="5" type="primary" onClick={this.switchDraw}>
                    制造工艺
                  </Button>
                  <DocHelper page="up3e60" />
                </Space>
                <Tabs defaultActiveKey={defTab} activeKey={defTab} onChange={this.tabSwitch}>
                  <TabPane tab={<Badge count={jobErr}>工单</Badge>} key="1">
                    <Form.Item name={['JobHead', 'id']} hidden={true}>
                      <Input />
                    </Form.Item>
                    <Form.Item label="工单号">
                      <Input.Group compact>
                        <JobSelect
                          width={120}
                          noStyle
                          name={['JobHead', 'jobNum']}
                          rules={[{ required: true, message: '工单号必填' }]}
                          setCurrent={this.getObj}
                          disabled={isAuto}
                        />
                        <Form.Item
                          name={['JobHead', 'isAuto']}
                          valuePropName="checked"
                          style={{ marginBottom: 0, marginLeft: 16 }}>
                          <Checkbox onChange={(e) => this.setAutoJob(e)}>自动编号</Checkbox>
                        </Form.Item>
                      </Input.Group>
                    </Form.Item>
                    <Form.Item label="物料">
                      <Input.Group compact>
                        <PartSelect
                          name={['JobHead', 'partNum']}
                          noStyle
                          width={120}
                          required={true}
                          placeholder="物料编码"
                          setCurrent={this.setCurrent}
                          pType="M"
                        />
                        <Form.Item noStyle name={['JobHead', 'revisionNum']}>
                          {selectRev}
                        </Form.Item>
                      </Input.Group>
                    </Form.Item>
                    <Form.Item name={['JobHead', 'partDescription']} label="描述">
                      <Input disabled />
                    </Form.Item>
                    <EmpSelect
                      showSearch
                      width={200}
                      name={['JobHead', 'personID']}
                      label="计划员"
                    />
                    <Form.Item
                      name={['JobHead', 'jobType']}
                      label="工单类型"
                      rules={[{ required: true, message: '工单类型必填' }]}
                    >
                      <Select
                        style={{ width: 200 }}
                        placeholder="请选择工单类型"
                        onChange={(e) => this.setState({ jobType: e })}
                      >
                        <Select.Option value="MTO">订单生产</Select.Option>
                        <Select.Option value="MTS">库存生产</Select.Option>
                        <Select.Option value="MTJ">工单生产</Select.Option>
                      </Select>
                    </Form.Item>
                    <Form.Item style={{ marginBottom: 0 }} wrapperCol={{ offset: 3 }}>
                      <Input.Group compact>
                        <Form.Item name={['JobHead', 'jobFirm']} valuePropName="checked">
                          <Checkbox>已确认</Checkbox>
                        </Form.Item>
                        <Form.Item name={['JobHead', 'jobClosed']} valuePropName="checked">
                          <Checkbox disabled>已完结</Checkbox>
                        </Form.Item>
                        <Form.Item name={['JobHead', 'jobCompleted']} valuePropName="checked">
                          <Checkbox disabled>已完成</Checkbox>
                        </Form.Item>
                        <Form.Item name={['JobHead', 'jobReleased']} valuePropName="checked">
                          <Checkbox onChange={this.releaseJob}>已发放</Checkbox>
                        </Form.Item>
                      </Input.Group>
                    </Form.Item>
                    <Form.Item
                      name={['JobHead', 'dueDate']}
                      label="需求日期"
                      rules={[{ required: true, message: '请选择订单日期' }]}
                    >
                      <DatePicker />
                    </Form.Item>
                    <Form.Item label="生产数量">
                      <Input.Group compact>
                        <Form.Item
                          noStyle
                          name={['JobHead', 'prodQty']}
                          rules={[{ required: true, message: '生产数量必填' }]}
                        >
                          <InputNumber min={1} />
                        </Form.Item>
                        <Form.Item
                          noStyle
                          name={['JobHead', 'ium']}
                          rules={[{ required: true, message: '单位必填' }]}
                        >
                          <Input disabled style={{ width: 80 }} placeholder="IUM" />
                        </Form.Item>
                      </Input.Group>
                    </Form.Item>
                    <Form.Item label="订单号">
                      <Input.Group compact>
                        <Form.Item noStyle name={['JobHead', 'orderNum']}>
                          <Input style={{ width: 100 }} disabled={jobType != 'MTO'} />
                        </Form.Item>
                        <Form.Item noStyle name={['JobHead', 'orderLine']}>
                          <Input style={{ width: 50 }} disabled={jobType != 'MTO'} />
                        </Form.Item>
                        <Form.Item noStyle name={['JobHead', 'orderRelNum']}>
                          <Input style={{ width: 50 }} disabled={jobType != 'MTO'} />
                        </Form.Item>
                        <Form.Item noStyle>
                          <ItemSelect
                            width={780}
                            control="OrderHed"
                            columns={columnOrderRel}
                            text="选择"
                            title="销售订单"
                            act="GetItems"
                            btntype="primary"
                            disabled={jobType != 'MTO'}
                            setCurrent={this.setSoCurrent}
                          />
                        </Form.Item>
                      </Input.Group>
                    </Form.Item>
                    <Form.Item label="上级工单">
                      <Input.Group compact>
                        <Form.Item noStyle name={['JobHead', 'parentJobNum']}>
                          <Input style={{ width: 100 }} disabled={jobType != 'MTJ'} />
                        </Form.Item>
                        <Form.Item noStyle name={['JobHead', 'parentJobAsmbl']}>
                          <Input style={{ width: 50 }} disabled={jobType != 'MTJ'} />
                        </Form.Item>
                        <Form.Item noStyle name={['JobHead', 'parentJobMtl']}>
                          <Input style={{ width: 50 }} disabled={jobType != 'MTJ'} />
                        </Form.Item>
                        <Form.Item noStyle>
                          <ItemSelect
                            width={780}
                            control="JobHead"
                            columns={columnJobItem}
                            text="选择"
                            title="工单物料"
                            act="getItems"
                            disabled={jobType != 'MTJ'}
                            setCurrent={this.setJobHeadParent}
                          />
                        </Form.Item>
                      </Input.Group>
                    </Form.Item>
                  </TabPane>
                  <TabPane tab={<Badge count={jobMtlErr}>物料</Badge>} key="2">
                    <Row>
                      <Col span={22}>
                        <Form.Item name={['JobMtl', 'id']} hidden={true}>
                          <Input />
                        </Form.Item>
                        <Form.Item name={['JobMtl', 'jobNum']} hidden={true}>
                          <Input />
                        </Form.Item>
                        <Form.Item name={['JobMtl', 'assemblySeq']} hidden={true}>
                          <Input />
                        </Form.Item>
                        <Form.Item name={['JobMtl', 'mtlSeq']} label="物料序号">
                          <InputNumber min={1} step={1} disabled />
                        </Form.Item>
                        <Form.Item label="物料编码">
                          <Input.Group compact>
                            <PartSelect
                              name={['JobMtl', 'partNum']}
                              noStyle
                              width={120}
                              required={true}
                              placeholder="物料编码"
                              setCurrent={this.setCurrent2}
                            />
                          </Input.Group>
                        </Form.Item>
                        <Form.Item name={['JobMtl', 'partDescription']} label="描述">
                          <Input disabled />
                        </Form.Item>
                        <Form.Item style={{ marginBottom: 0 }} label="相关工序">
                          <Input.Group compact>
                            <Form.Item name={['JobMtl', 'relatedOperation']}>
                              <Select style={{ width: 200 }} onChange={this.selectOpr}>
                                {booList?.map((item: any) => {
                                  return (
                                    <Select.Option value={item.item.oprSeq} key={item.item.id}>
                                      {item.item.oprSeq} - {item.item.opDesc}
                                    </Select.Option>
                                  );
                                })}
                              </Select>
                            </Form.Item>
                            <Form.Item name={['JobMtl', 'relatedOpRev']}>
                              <Input placeholder="工序版本" style={{ width: 50 }} />
                            </Form.Item>
                          </Input.Group>
                        </Form.Item>
                        <Form.Item label="数量/父项" style={{ marginBottom: 0 }}>
                          <Input.Group compact>
                            <Form.Item
                              name={['JobMtl', 'qtyPer']}
                              rules={[{ required: true, message: '需求数量必填' }]}
                            >
                              <InputNumber min={1} style={{ width: 120, marginRight: 10 }} disabled />
                            </Form.Item>
                            <Form.Item name={['JobMtl', 'fixedQty']} valuePropName="checked">
                              <Checkbox>固定数量</Checkbox>
                            </Form.Item>
                          </Input.Group>
                        </Form.Item>
                        <Form.Item label="需求数量">
                          <Input.Group compact>
                            <Form.Item
                              noStyle
                              name={['JobMtl', 'requiredQty']}
                              rules={[{ required: true, message: '需求数量必填' }]}
                            >
                              <InputNumber min={1} />
                            </Form.Item>
                            <Form.Item
                              noStyle
                              name={['JobMtl', 'ium']}
                              rules={[{ required: true, message: '单位必填' }]}
                            >
                              <Input disabled style={{ width: 70 }} placeholder="单位" />
                            </Form.Item>
                          </Input.Group>
                        </Form.Item>
                        <Form.Item style={{ marginBottom: 0 }} wrapperCol={{ offset: 3 }}>
                          <Input.Group compact>
                            <Form.Item name={['JobMtl', 'issueComplete']} valuePropName="checked">
                              <Checkbox>发料完成</Checkbox>
                            </Form.Item>
                            <Form.Item name={['JobMtl', 'direct']} valuePropName="checked">
                              <Checkbox>直接生产</Checkbox>
                            </Form.Item>
                            <Form.Item name={['JobMtl', 'buyIt']} valuePropName="checked">
                              <Checkbox>直接采购</Checkbox>
                            </Form.Item>
                            <Form.Item
                              name={['JobMtl', 'rcvInspectionReq']}
                              valuePropName="checked"
                            >
                              <Checkbox>需要检验</Checkbox>
                            </Form.Item>
                          </Input.Group>
                        </Form.Item>
                      </Col>
                      <Col span={2}></Col>
                    </Row>
                  </TabPane>
                  <TabPane tab={<Badge count={jobAsmErr}>半成品</Badge>} key="3">
                    <Row>
                      <Col span={22}>
                        <Form.Item name={['JobAsmbl', 'id']} hidden>
                          <Input />
                        </Form.Item>
                        <Form.Item name={['JobAsmbl', 'jobNum']} hidden>
                          <Input />
                        </Form.Item>
                        <Form.Item name={['JobAsmbl', 'parent']} hidden>
                          <Input />
                        </Form.Item>
                        <Form.Item name={['JobAsmbl', 'assemblySeq']} label="半成品号">
                          <InputNumber min={1} step={1} disabled />
                        </Form.Item>
                        <Form.Item label="物料编码">
                          <Input.Group compact>
                            <PartSelect
                              name={['JobAsmbl', 'partNum']}
                              noStyle
                              width={120}
                              required={true}
                              placeholder="物料编码"
                              setCurrent={this.setCurrent3}
                              pType="M"
                            />
                            <Form.Item noStyle name={['JobAsmbl', 'revisionNum']}>
                              {selectRev2}
                            </Form.Item>
                          </Input.Group>
                        </Form.Item>
                        <Form.Item name={['JobAsmbl', 'partDescription']} label="描述">
                          <Input disabled />
                        </Form.Item>

                        <Form.Item label="数量/父项" style={{ marginBottom: 0 }}>
                          <Input.Group compact>
                            <Form.Item
                              noStyle
                              name={['JobAsmbl', 'qtyPer']}
                              rules={[{ required: true, message: '需求数量必填' }]}
                            >
                              <InputNumber min={1} style={{ width: 120, marginRight: 10 }} disabled/>
                            </Form.Item>
                            <Form.Item name={['JobAsmbl', 'fixedQty']} valuePropName="checked">
                              <Checkbox>固定数量</Checkbox>
                            </Form.Item>
                          </Input.Group>
                        </Form.Item>
                        <Form.Item label="需求数量">
                          <Input.Group compact>
                            <Form.Item
                              noStyle
                              name={['JobAsmbl', 'requiredQty']}
                              rules={[{ required: true, message: '需求数量必填' }]}
                            >
                              <InputNumber min={1} style={{ width: 120 }} />
                            </Form.Item>
                            <Form.Item
                              noStyle
                              name={['JobAsmbl', 'ium']}
                              rules={[{ required: true, message: '单位必填' }]}
                            >
                              <Input disabled style={{ width: 70 }} placeholder="单位" />
                            </Form.Item>
                          </Input.Group>
                        </Form.Item>
                        <Form.Item
                          name={['JobAsmbl', 'direct']}
                          valuePropName="checked"
                          wrapperCol={{ offset: 3 }}
                        >
                          <Checkbox>直接生产</Checkbox>
                        </Form.Item>
                      </Col>
                      <Col span={2}></Col>
                    </Row>
                  </TabPane>
                  <TabPane tab={<Badge count={jobOprErr}>工序</Badge>} key="4">
                    <Row>
                      <Col span={22}>
                        <Form.Item name={['JobOper', 'id']} hidden={true}>
                          <Input />
                        </Form.Item>
                        <Form.Item name={['JobOper', 'jobNum']} hidden={true}>
                          <Input />
                        </Form.Item>
                        <Form.Item name={['JobOper', 'partDescription']} hidden={true}>
                          <Input />
                        </Form.Item>
                        <Form.Item name={['JobOper', 'partNum']} hidden={true}>
                          <Input />
                        </Form.Item>
                        <Form.Item name={['JobOper', 'revisionNum']} hidden={true}>
                          <Input />
                        </Form.Item>
                        <Form.Item name={['JobOper', 'assemblySeq']} label="半成品号">
                          <InputNumber min={1} step={1} disabled />
                        </Form.Item>
                        <Form.Item name={['JobOper', 'oprSeq']} label="序号">
                          <InputNumber min={0} step={10} />
                        </Form.Item>
                        <Form.Item label="生产标准">
                          <Input.Group compact>
                            <Form.Item
                              noStyle
                              name={['JobOper', 'prodStandard']}
                              rules={[{ required: true, message: '请输入生产标准' }]}
                            >
                              <Input style={{ width: 200 }} />
                            </Form.Item>
                            <Form.Item noStyle name={['JobOper', 'stdFormat']}>
                              <Select placeholder="小时/件" style={{ width: 90 }}>
                                <Select.Option value="HP">小时/件</Select.Option>
                                <Select.Option value="MP">分钟/件</Select.Option>
                                <Select.Option value="PM">件/分钟</Select.Option>
                                <Select.Option value="OH">件/小时</Select.Option>
                              </Select>
                            </Form.Item>
                          </Input.Group>
                        </Form.Item>
                        <OpMasterSelect
                          width={200}
                          labelInValue={false}
                          required={false}
                          showSearch={false}
                          name={['JobOper', 'opCode']}
                          label="工序"
                        />
                        <Form.Item style={{ marginBottom: 0 }} wrapperCol={{ offset: 3 }}>
                          <Input.Group compact>
                            <Form.Item name={['JobOper', 'subContract']} valuePropName="checked">
                              <Checkbox>外包</Checkbox>
                            </Form.Item>
                            <Form.Item name={['JobOper', 'finalOpr']} valuePropName="checked">
                              <Checkbox>最后工序</Checkbox>
                            </Form.Item>
                            <Form.Item name={['JobOper', 'autoReceive']} valuePropName="checked">
                              <Checkbox>自动收货</Checkbox>
                            </Form.Item>
                            <Form.Item name={['JobOper', 'opComplete']} valuePropName="checked">
                              <Checkbox disabled>完成</Checkbox>
                            </Form.Item>
                          </Input.Group>
                        </Form.Item>
                        <Form.Item
                          name={['JobOper', 'schedRelation']}
                          label="排程方式"
                          rules={[{ required: true, message: '请选择排程方式' }]}
                        >
                          <Radio.Group>
                            <Radio value="SS">开始-到-开始</Radio>
                            <Radio value="FS">结束-到-开始</Radio>
                            <Radio value="FF">结束-到-结束</Radio>
                          </Radio.Group>
                        </Form.Item>
                        <ResourceGrpSelect
                          width={200}
                          required={true}
                          showSearch={false}
                          name={['JobOper', 'resourceGrpID']}
                          label="资源群组"
                        />
                        <ResourceSelect
                          width={200}
                          required={true}
                          showSearch={false}
                          name={['JobOper', 'resourceID']}
                          label="资源"
                        />
                        <Form.Item label="工序备注" name={['JobOper', 'commentText']}>
                          <Input.TextArea rows={5} />
                        </Form.Item>
                      </Col>
                      <Col span={2}></Col>
                    </Row>
                  </TabPane>
                </Tabs>
              </Card>
            </Col>
          </Row>
        </Form>
      </PageHeaderWrapper>
    );
  }
}
export default connect(({ Abp }: API.IConnectState) => ({
  response: Abp.response,
  currentUser: Abp.currentUser,
}))(ViewPage);
